/*
 * $Id: errno.h,v 1.18 2006-03-21 16:15:16 bacon Exp $
 */

#ifndef _XP_BAS_ERRNO_H_
#define _XP_BAS_ERRNO_H_

#include <xp/types.h>
#include <xp/macros.h>

#ifndef _WIN32_WCE
#include <errno.h>
#endif

#define xp_errno errno

#define XP_ERRNO_BASE    776549
#define XP_ERRNO_SCKBASE 876549

#ifdef ENOSYS
	#define XP_ENOSYS ENOSYS
#else
	#define XP_ENOSYS (XP_ERRNO_BASE + 1)
#endif

#ifdef EINVAL
	#define XP_EINVAL EINVAL
#else
	#define XP_EINVAL (XP_ERRNO_BASE + 2)
#endif

#ifdef EFAULT
	#define XP_EFAULT EFAULT
#else
	#define XP_EFAULT (XP_ERRNO_BASE + 3)
#endif

#ifdef EBADF
	#define XP_EBADF EBADF
#else
	#define XP_EBADF (XP_ERRNO_BASE + 4)
#endif

#ifdef EINTR
	#define XP_EINTR EINTR
#else
	#define XP_EINTR (XP_ERRNO_BASE + 5)
#endif

#ifdef ENOTSUP
	#define XP_ENOTSUP ENOTSUP
#else
	#define XP_ENOTSUP (XP_ERRNO_BASE + 6)
#endif

#ifdef EACCES
	#define XP_EACCES EACCES
#else
	#define XP_EACCES (XP_ERRNO_BASE + 7)
#endif

#ifdef EPERM
	#define XP_EPERM EPERM
#else
	#define XP_EPERM (XP_ERRNO_BASE + 8)
#endif

#ifdef ENOENT
	#define XP_ENOENT ENOENT
#else
	#define XP_ENOENT (XP_ERRNO_BASE + 9)
#endif

#ifdef EMFILE
	#define XP_EMFILE EMFILE
#else
	#define XP_EMFILE (XP_ERRNO_BASE + 9)
#endif

#ifdef EAGAIN
	#define XP_EAGAIN EAGAIN
#else
	#define XP_EAGAIN (XP_ERRNO_BASE + 10)
#endif

#ifdef ERANGE
	#define XP_ERANGE ERANGE
#else
	#define XP_ERANGE (XP_ERRNO_BASE + 11)
#endif

#ifdef EBUSY
	#define XP_EBUSY EBUSY
#else
	#define XP_EBUSY (XP_ERRNO_BASE + 12)
#endif

#ifdef EXDEV
	#define XP_EXDEV EXDEV
#else
	#define XP_EXDEV (XP_ERRNO_BASE + 13)
#endif

#ifdef EEXIST
	#define XP_EEXIST EEXIST
#else
	#define XP_EEXIST (XP_ERRNO_BASE + 14)
#endif

#ifdef ENOEXEC
	#define XP_ENOEXEC ENOEXEC
#else
	#define XP_ENOEXEC (XP_ERRNO_BASE + 15)
#endif

#ifdef ECHILD
	#define XP_ECHILD ECHILD
#else
	#define XP_ECHILD (XP_ERRNO_BASE + 16)
#endif

#ifdef ENOTEMPTY
	#define XP_ENOTEMPTY ENOTEMPTY
#else
	#define XP_ENOTEMPTY (XP_ERRNO_BASE + 17)
#endif

#ifdef EPIPE
	#define XP_EPIPE EPIPE
#else
	#define XP_EPIPE (XP_ERRNO_BASE + 18)
#endif

#ifdef E2BIG
	#define XP_E2BIG E2BIG
#else
	#define XP_E2BIG (XP_ERRNO_BASE + 19)
#endif

#ifdef ENOMEM
	#define XP_ENOMEM ENOMEM
#else
	#define XP_ENOMEM (XP_ERRNO_BASE + 20)
#endif

#ifdef ENOSPC
	#define XP_ENOSPC ENOSPC
#else
	#define XP_ENOSPC (XP_ERRNO_BASE + 21)
#endif

#ifdef ECANCELED
	#define XP_ECANCELED ECANCELED
#else
	#define XP_ECANCELED (XP_ERRNO_BASE + 22)
#endif

#ifdef EILSEQ
	#define XP_EILSEQ EILSEQ
#else
	#define XP_EILSEQ (XP_ERRNO_BASE + 23)
#endif

#ifdef ENOBUFS
	#define XP_ENOBUFS ENOBUFS
#else
	#define XP_ENOBUFS (XP_ERRNO_BASE + 24)
#endif


/* socket errors */
#ifdef EADDRINUSE
	#define XP_EADDRINUSE EADDRINUSE
#else
	#define XP_EADDRINUSE (XP_ERRNO_SCKBASE + 1)
#endif

#ifdef EADDRNOTAVAIL
	#define XP_EADDRNOTAVAIL EADDRNOTAVAIL
#else
	#define XP_EADDRNOTAVAIL (XP_ERRNO_SCKBASE + 2)
#endif

#ifdef EAFNOSUPPORT
	#define XP_EAFNOSUPPORT EAFNOSUPPORT
#else
	#define XP_EAFNOSUPPORT (XP_ERRNO_SCKBASE + 3)
#endif

#ifdef EALREADY
	#define XP_EALREADY EALREADY
#else
	#define XP_EALREADY (XP_ERRNO_SCKBASE + 4)
#endif

#ifdef ECONNABORTED
	#define XP_ECONNABORTED ECONNABORTED
#else
	#define XP_ECONNABORTED (XP_ERRNO_SCKBASE + 5)
#endif

#ifdef ECONNREFUSED
	#define XP_ECONNREFUSED ECONNREFUSED
#else
	#define XP_ECONNREFUSED (XP_ERRNO_SCKBASE + 6)
#endif

#ifdef ECONNRESET
	#define XP_ECONNRESET ECONNRESET
#else
	#define XP_ECONNRESET (XP_ERRNO_SCKBASE + 7)
#endif

#ifdef EINPROGRESS
	#define XP_EINPROGRESS EINPROGRESS
#else
	#define XP_EINPROGRESS (XP_ERRNO_SCKBASE + 8)
#endif

#ifdef ENETDOWN
	#define XP_ENETDOWN ENETDOWN
#else
	#define XP_ENETDOWN (XP_ERRNO_SCKBASE + 9)
#endif

#ifdef ENETRESET
	#define XP_ENETRESET ENETRESET
#else
	#define XP_ENETRESET (XP_ERRNO_SCKBASE + 10)
#endif

#ifdef ENETUNREACH
	#define XP_ENETUNREACH ENETUNREACH
#else
	#define XP_ENETUNREACH (XP_ERRNO_SCKBASE + 11)
#endif

#ifdef ENOTCONN
	#define XP_ENOTCONN ENOTCONN
#else
	#define XP_ENOTCONN (XP_ERRNO_SCKBASE + 12)
#endif

#ifdef ENOTSOCK
	#define XP_ENOTSOCK ENOTSOCK
#else
	#define XP_ENOTSOCK (XP_ERRNO_SCKBASE + 13)
#endif

#ifdef EPROTONOSUPPORT
	#define XP_EPROTONOSUPPORT EPROTONOSUPPORT
#else
	#define XP_EPROTONOSUPPORT (XP_ERRNO_SCKBASE + 14)
#endif

#ifdef ETIMEDOUT
	#define XP_ETIMEDOUT ETIMEDOUT
#else
	#define XP_ETIMEDOUT (XP_ERRNO_SCKBASE + 15)
#endif

#ifdef EWOULDBLOCK
	#define XP_EWOULDBLOCK EWOULDBLOCK
#else
	#define XP_EWOULDBLOCK (XP_ERRNO_SCKBASE + 16)
#endif

/* end of socket errors */


#ifdef __cplusplus
extern "C" {
#endif

#ifdef _WIN32
int xp_maperrno (unsigned long oserrno);
int xp_maperrno_wsa (int oserrno);
#endif

int xp_geterrno (void);
void xp_seterrno (int num);

#ifdef __cplusplus
}
#endif

#endif
